package com.cskaoyan.com.ex;

import com.cskaoyan.com.stack.MyArrayStack;

/**
 *   翻转字符串
 *   括号匹配问题
 */
public class ExStack1 {
    public static void main(String[] args) {

        String str = "123456789";

        // "987654321"
        String str2 = reString(str);
        System.out.println(str2);

    }

    private static String reString(String str) {
        // 需要一个栈
        MyArrayStack<Character> stack = new MyArrayStack<>();

        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }

        // 出栈拼接
        StringBuffer buffer = new StringBuffer();

        // 栈不空一直出栈
        while (!stack.isEmpty()){
            Character pop = stack.pop();
            buffer.append(pop);
        }

        return buffer.toString();
    }
}
